//
//  PayFoodTableViewCell.m
//  Menu
//
//  Created by dllo on 15/7/7.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "PayFoodTableViewCell.h"

@implementation PayFoodTableViewCell

- (void)dealloc
{
    [_scienceImgView release];
    [_scienceLabel release];
    [_promptLabel release];
    [_promptTextLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.scienceImgView = [[UIImageView alloc] initWithFrame:CGRectMake(30*WIDTH, 10*HEIGHT, 315*WIDTH, 200*HEIGHT)];
    [self.contentView addSubview:self.scienceImgView];
    [_scienceImgView release];
    
    self.scienceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 230*HEIGHT, 355*WIDTH, 300*HEIGHT)];
    self.scienceLabel.numberOfLines = 0;
    self.scienceLabel.font = [UIFont systemFontOfSize:17];
    self.scienceLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.scienceLabel];
    [_scienceLabel release];
    
    _promptLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 230*HEIGHT + 300*HEIGHT , 200*WIDTH, 30*HEIGHT)];
    _promptLabel.backgroundColor = [UIColor whiteColor];
    _promptLabel.text = @"温馨提示";
//    [_promptLabel sizeToFit];
    [self.contentView addSubview:_promptLabel];
    [_promptLabel release];
    
    self.promptTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 210*HEIGHT + 300*HEIGHT + 30*HEIGHT + 10*HEIGHT, 355*WIDTH, 100*HEIGHT)];
    self.promptTextLabel.font = [UIFont systemFontOfSize:17];
    self.promptTextLabel.numberOfLines = 0;
    self.promptTextLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.promptTextLabel];
    [_promptTextLabel release];

}

-(void)setPayFoodModel:(PayFoodModel *)payFoodModel
{
    if (_payFoodModel != payFoodModel)
    {
        [_payFoodModel release];
        _payFoodModel = [payFoodModel retain];
    }
    [self.scienceImgView sd_setImageWithURL:[NSURL URLWithString:payFoodModel.nousImage]];
    NSString *scienceStr = [NSString stringWithFormat:@"        %@",payFoodModel.scienceNous];
    NSString *promptStr= [NSString stringWithFormat:@"        %@",payFoodModel.meekPrompt];
    self.scienceLabel.text = scienceStr;
    self.promptTextLabel.text = promptStr;
    CGFloat LabelHeight = [[self class] heightForcell:scienceStr];
    self.scienceLabel.frame = CGRectMake(10*WIDTH, 230*HEIGHT, 355*WIDTH, LabelHeight);
    _promptLabel.frame = CGRectMake(10*WIDTH, 230*HEIGHT + LabelHeight + 10*HEIGHT, 100*WIDTH, 30*HEIGHT);
    NSLog(@"%f",_promptLabel.frame.origin.y);
    CGFloat promptHeight = [[self class] heightForcell:promptStr];
    _promptTextLabel.frame = CGRectMake(10*WIDTH, 270*HEIGHT+LabelHeight, 355*WIDTH, promptHeight);
    
}
+(CGFloat)heightForcell:(NSString *)content
{
    //参数1.设置计算内容的宽和高
    //参数2.设置计算高度模式
    //参数3.设置计算字体大小属性
    //参数4.系统备用参数,设置为nil
    //其中宽度一定与显示内容的label宽度一致否则计算不准确  高度尽量大一些
    CGSize size=CGSizeMake(355*WIDTH, 10000);
    //字体大小一定与显示内容的label字体大小一致  默认是17.0
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    
    CGRect frame=  [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}





































- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
